<?php

namespace app\api\controller\v1;

use think\Request;
use app\common\controller\BaseController;
use app\common\validate\UserValidate;
use app\common\model\User as UserModel;

class User extends BaseController
{
    // 发送验证码
    public function sendcode()
    {
        // 验证码参数
        (new UserValidate())->goCheck('sendcode');
        (new UserModel())->sendcode();
        return self::showResCodeWithOutData('发送成功');
    }
    // 手机号登录
    public function phoneLogin()
    {
        // 验证登陆信息
        (new UserValidate())->goCheck('phonelogin');
        // 手机登录
        $token = (new userModel())->phoneLogin();
        return self::showResCode('登陆成功',['token' => $token]);
    }
    // 账号密码登陆
    public function login()
    {
         // 验证登陆信息
        (new UserValidate())->goCheck('login');
        // 登陆
        $token = (new userModel())->login();
        return self::showResCode('登陆成功',['token' => $token]);
    }
    //  第三方登陆
    public function otherLogin()
    {
        (new UserValidate())->goCheck('otherlogin');
         // 登陆
         $token = (new userModel())->otherlogin();
         return self::showResCode('登陆成功',['token' => $token]);
    }

    // 退出登陆
    public function loginout()
    {
       (new UserModel())->loginout();
       return $this->showResCodeWithOutData('退出成功');
    }

    // 指定用户下的文章列表
    public function post()
    {   
        (new UserValidate())->goCheck('post');
        $list = (new UserModel())->getPost();
        return self::showResCode('获取成功',['list' => $list]); 
    }

    // 用户下的所有文章列表
    public function postAll()
    {
        (new UserValidate)->goCheck('postall');
        $list = (new UserModel())->getPostAll();
        return self::showResCode('获取成功',['list' => $list]); 
    }
    // 用户绑定手机号
    public function bindphone(){
        (new UserValidate())->goCheck('bindphone');
        // 绑定
        (new UserModel())->bindphone();
        return self::showResCodeWithOutData('绑定成功');
    }
    // 用户绑定邮箱
    public function bindemail()
    {
        (new UserValidate())->goCheck('bindemail');
        // 绑定邮箱
        (new UserModel())->bindemail();
        return self::showResCodeWithOutData('绑定成功');
    }
    // 修改头像
    public function editUserpic()
    {
        (new UserValidate())->goCheck('edituserpic');
        (new UserModel())->editUserpic();
        return self::showResCodeWithOutData('修改成功');
    }
    // 修改资料
    public function editinfo()
    {
        (new UserValidate())->goCheck('edituserinfo');
        (new UserModel())->editUserinfo();
        return self::showResCodeWithOutData('修改成功');
    }
    // 修改密码
    public function rePassword()
    {   
        (new UserValidate())->goCheck('repassword');
        (new UserModel())->rePassword();
        return self::showResCodeWithOutData('修改成功');
    }
    // 关注
    public function follow()
    {
        (new UserValidate())->goCheck('follow');
        (new UserModel())->ToFollow();
        return $this->showResCodeWithOutData('关注成功');
    }
    // 取消关注
    public function unfollow()
    {
        (new UserValidate())->goCheck('follow');
        (new UserModel())->unFollow();
        return $this->showResCodeWithOutData('取消成功');
    }
    // 互关列表
    public function friends()
    {
        (new UserValidate())->goCheck('getfriends');
        $list = (new UserModel())->getFriendslist();
        return self::showResCode('获取成功',['list' => $list]); 
    }
    // 粉丝列表
    public function fens()
    {
        (new UserValidate())->goCheck('getfens');
        $list = (new UserModel())->getfenslist();
        return self::showResCode('获取成功',['list' => $list]); 
    }
    // 关注列表
    public function follows()
    {
        (new UserValidate())->goCheck('getfollows');
        $list = (new UserModel())->getfollowslist();
        return self::showResCode('获取成功',['list' => $list]); 
    }
}
